package BoostedTest::RDBO::Testplan;

use strict;

use base qw(BoostedTest::RDBO::DB::Object);

__PACKAGE__->meta->setup(
    table   => 'testplans',

    columns => [
        id          => { type => 'serial', not_null => 1 },
        users_id    => { type => 'integer', default => '0', not_null => 1 },
        language_id => { type => 'integer', default => '0', not_null => 1 },
        name        => { type => 'varchar', length => 255 },
        description => { type => 'varchar', length => 255 },
        content     => { type => 'text', length => 65535 },
        created     => { type => 'datetime' },
        modified    => { type => 'datetime' },
    ],

    foreign_keys =>
    [
      user =>
      {
        class       => 'BoostedTest::RDBO::User',
        key_columns => { users_id => 'id' },
      },

      language =>
      {
        class       => 'BoostedTest::RDBO::Language',
        key_columns => { language_id => 'id' },
      },
    ],

    relationships => [
        components =>
        {
          type      => 'many to many',
          map_class => 'BoostedTest::RDBO::ComponentsHasTestplan',
          map_from  => 'testplan',
          map_to    => 'component',
        },
      ],
    primary_key_columns => [ 'id' ],
);


__PACKAGE__->meta->column('created')->add_trigger(
    event => 'on_save',
    code  => sub {
        my $self  = shift;
        my $value = $self->created;
        $self->created(time);

    }
);

__PACKAGE__->meta->column('modified')->add_trigger(
    event => 'on_save',
    code  => sub {
        my $self  = shift;
        my $value = $self->modified;
        $self->created(time);

    }
);

1;

